<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<title>Custom Tags in JSP Pages - The Java EE 5 Tutorial</title>
<meta name="robots" content="index,follow">
<meta name="robots" content="index,follow">
<meta name="date" content="2008-10-01">
<link rel="stylesheet" type="text/css" href="css/default.css">
<link rel="stylesheet" type="text/css" href="css/ipg.css">
<link rel="stylesheet" type="text/css" href="css/j5eetutorial.css">
</head>

<body>

<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tbody>
   <tr valign="top">
      <td><p class="toc level1"><a href="docinfo.html">Document Information</a></p>
<p class="toc level1 tocsp"><a href="gexaf.html">Preface</a></p>
<p class="toc level1 tocsp"><a href="gfirp.html">Part&nbsp;I&nbsp;Introduction</a></p>
<p class="toc level2"><a href="bnaaw.html">1.&nbsp;&nbsp;Overview</a></p>
<p class="toc level2"><a href="gfiud.html">2.&nbsp;&nbsp;Using the Tutorial Examples</a></p>
<p class="toc level1 tocsp"><a href="bnadp.html">Part&nbsp;II&nbsp;The Web Tier</a></p>
<p class="toc level2"><a href="bnadr.html">3.&nbsp;&nbsp;Getting Started with Web Applications</a></p>
<p class="toc level2"><a href="bnafd.html">4.&nbsp;&nbsp;Java Servlet Technology</a></p>
<p class="toc level2"><a href="bnagx.html">5.&nbsp;&nbsp;JavaServer Pages Technology</a></p>
<p class="toc level2"><a href="bnajo.html">6.&nbsp;&nbsp;JavaServer Pages Documents</a></p>
<p class="toc level2"><a href="bnakc.html">7.&nbsp;&nbsp;JavaServer Pages Standard Tag Library</a></p>
<div class="onpage">
<p class="toc level2"><a href="">8.&nbsp;&nbsp;Custom Tags in JSP Pages</a></p>
</div>
<p class="toc level3"><a href="bnalk.html">What Is a Custom Tag?</a></p>
<p class="toc level3"><a href="bnall.html">The Example JSP Pages</a></p>
<p class="toc level3"><a href="bnaln.html">Types of Tags</a></p>
<p class="toc level4"><a href="bnaln.html#bnalo">Tags with Attributes</a></p>
<p class="toc level5"><a href="bnaln.html#bnalp">Simple Attributes</a></p>
<p class="toc level5"><a href="bnaln.html#bnalq">Fragment Attributes</a></p>
<p class="toc level5"><a href="bnaln.html#bnalr">Dynamic Attributes</a></p>
<p class="toc level5"><a href="bnaln.html#bnals">Deferred Value</a></p>
<p class="toc level5"><a href="bnaln.html#bnalt">Deferred Method</a></p>
<p class="toc level5"><a href="bnaln.html#bnalu">Dynamic Attribute or Deferred Expression</a></p>
<p class="toc level5"><a href="bnaln.html#bnalv"><tt>jsp:attribute</tt> Element</a></p>
<p class="toc level4 tocsp"><a href="bnaln.html#bnalw">Tags with Bodies</a></p>
<p class="toc level5"><a href="bnaln.html#bnalx"><tt>jsp:body</tt> Element</a></p>
<p class="toc level4 tocsp"><a href="bnaln.html#bnaly">Tags That Define Variables</a></p>
<p class="toc level4"><a href="bnaln.html#bnalz">Communication between Tags</a></p>
<p class="toc level3 tocsp"><a href="bnama.html">Encapsulating Reusable Content Using Tag Files</a></p>
<p class="toc level4"><a href="bnama.html#bnamb">Tag File Location</a></p>
<p class="toc level4"><a href="bnama.html#bnamc">Tag File Directives</a></p>
<p class="toc level5"><a href="bnama.html#bname">Declaring Tags</a></p>
<p class="toc level5"><a href="bnama.html#bnamg">body-content Attribute</a></p>
<p class="toc level5"><a href="bnama.html#bnamh">Declaring Tag Attributes in Tag Files</a></p>
<p class="toc level5"><a href="bnama.html#bnamj">Declaring Tag Variables in Tag Files</a></p>
<p class="toc level4 tocsp"><a href="bnama.html#bnamo">Evaluating Fragments Passed to Tag Files</a></p>
<p class="toc level4"><a href="bnama.html#bnamp">Custom Tag Examples</a></p>
<p class="toc level5"><a href="bnama.html#bnamq">Simple Attribute Example</a></p>
<p class="toc level5"><a href="bnama.html#bnamr">Simple and Fragment Attribute and Variable Example</a></p>
<p class="toc level5"><a href="bnama.html#bnams">Dynamic Attribute Example</a></p>
<p class="toc level3 tocsp"><a href="bnamu.html">Tag Library Descriptors</a></p>
<p class="toc level4"><a href="bnamu.html#bnamw">Top-Level Tag Library Descriptor Elements</a></p>
<p class="toc level5"><a href="bnamu.html#bnamx"><tt>validator</tt> Element</a></p>
<p class="toc level5"><a href="bnamu.html#bnamz"><tt>listener</tt> Element</a></p>
<p class="toc level4 tocsp"><a href="bnamu.html#bnana">Declaring Tag Files</a></p>
<p class="toc level5"><a href="bnamu.html#bnanb"><tt>tag-file</tt> TLD Element</a></p>
<p class="toc level5"><a href="bnamu.html#bnand">Unpackaged Tag Files</a></p>
<p class="toc level5"><a href="bnamu.html#bnane">Packaged Tag Files</a></p>
<p class="toc level4 tocsp"><a href="bnamu.html#bnanf">Declaring Tag Handlers</a></p>
<p class="toc level5"><a href="bnamu.html#bnanh"><tt>body-content</tt> Element</a></p>
<p class="toc level4 tocsp"><a href="bnamu.html#bnani">Declaring Tag Attributes for Tag Handlers</a></p>
<p class="toc level4"><a href="bnamu.html#bnank">Declaring Tag Variables for Tag Handlers</a></p>
<p class="toc level3 tocsp"><a href="bnann.html">Programming Simple Tag Handlers</a></p>
<p class="toc level4"><a href="bnann.html#bnano">Including Tag Handlers in Web Applications</a></p>
<p class="toc level4"><a href="bnann.html#bnanp">How Is a Simple Tag Handler Invoked?</a></p>
<p class="toc level4"><a href="bnann.html#bnanq">Tag Handlers for Basic Tags</a></p>
<p class="toc level4"><a href="bnann.html#bnanr">Tag Handlers for Tags with Attributes</a></p>
<p class="toc level5"><a href="bnann.html#bnans">Defining Attributes in a Tag Handler</a></p>
<p class="toc level5"><a href="bnann.html#bnant">Attribute Validation</a></p>
<p class="toc level5"><a href="bnann.html#bnanu">Setting Dynamic Attributes</a></p>
<p class="toc level5"><a href="bnann.html#bnanv">Setting Deferred Value Attributes and Deferred Method Attributes</a></p>
<p class="toc level4 tocsp"><a href="bnann.html#bnanw">Tag Handlers for Tags with Bodies</a></p>
<p class="toc level5"><a href="bnann.html#bnanx">Tag Handler Does Not Manipulate the Body</a></p>
<p class="toc level4 tocsp"><a href="bnann.html#bnanz">Tag Handlers for Tags That Define Variables</a></p>
<p class="toc level5"><a href="bnann.html#bnaob"><tt>TagExtraInfo</tt> Class</a></p>
<p class="toc level4 tocsp"><a href="bnann.html#bnaoc">Cooperating Tags</a></p>
<p class="toc level4"><a href="bnann.html#bnaod">Tag Handler Examples</a></p>
<p class="toc level5"><a href="bnann.html#bnaoe">An Iteration Tag</a></p>
<p class="toc level5"><a href="bnann.html#bnaoh">A Template Tag Library</a></p>
<p class="toc level2 tocsp"><a href="bnaon.html">9.&nbsp;&nbsp;Scripting in JSP Pages</a></p>
<p class="toc level2"><a href="bnaph.html">10.&nbsp;&nbsp;JavaServer Faces Technology</a></p>
<p class="toc level2"><a href="bnaqz.html">11.&nbsp;&nbsp;Using JavaServer Faces Technology in JSP Pages</a></p>
<p class="toc level2"><a href="bnatx.html">12.&nbsp;&nbsp;Developing with JavaServer Faces Technology</a></p>
<p class="toc level2"><a href="bnavg.html">13.&nbsp;&nbsp;Creating Custom UI Components</a></p>
<p class="toc level2"><a href="bnawo.html">14.&nbsp;&nbsp;Configuring JavaServer Faces Applications</a></p>
<p class="toc level2"><a href="bnaxu.html">15.&nbsp;&nbsp;Internationalizing and Localizing Web Applications</a></p>
<p class="toc level1 tocsp"><a href="bnayk.html">Part&nbsp;III&nbsp;Web Services</a></p>
<p class="toc level2"><a href="bnayl.html">16.&nbsp;&nbsp;Building Web Services with JAX-WS</a></p>
<p class="toc level2"><a href="bnazf.html">17.&nbsp;&nbsp;Binding between XML Schema and Java Classes</a></p>
<p class="toc level2"><a href="bnbdv.html">18.&nbsp;&nbsp;Streaming API for XML</a></p>
<p class="toc level2"><a href="bnbhf.html">19.&nbsp;&nbsp;SOAP with Attachments API for Java</a></p>
<p class="toc level1 tocsp"><a href="bnblr.html">Part&nbsp;IV&nbsp;Enterprise Beans</a></p>
<p class="toc level2"><a href="bnbls.html">20.&nbsp;&nbsp;Enterprise Beans</a></p>
<p class="toc level2"><a href="bnbnb.html">21.&nbsp;&nbsp;Getting Started with Enterprise Beans</a></p>
<p class="toc level2"><a href="bnboc.html">22.&nbsp;&nbsp;Session Bean Examples</a></p>
<p class="toc level2"><a href="bnbpk.html">23.&nbsp;&nbsp;A Message-Driven Bean Example</a></p>
<p class="toc level1 tocsp"><a href="bnbpy.html">Part&nbsp;V&nbsp;Persistence</a></p>
<p class="toc level2"><a href="bnbpz.html">24.&nbsp;&nbsp;Introduction to the Java Persistence API</a></p>
<p class="toc level2"><a href="bnbrl.html">25.&nbsp;&nbsp;Persistence in the Web Tier</a></p>
<p class="toc level2"><a href="bnbrs.html">26.&nbsp;&nbsp;Persistence in the EJB Tier</a></p>
<p class="toc level2"><a href="bnbtg.html">27.&nbsp;&nbsp;The Java Persistence Query Language</a></p>
<p class="toc level1 tocsp"><a href="bnbwi.html">Part&nbsp;VI&nbsp;Services</a></p>
<p class="toc level2"><a href="bnbwj.html">28.&nbsp;&nbsp;Introduction to Security in the Java EE Platform</a></p>
<p class="toc level2"><a href="bnbyk.html">29.&nbsp;&nbsp;Securing Java EE Applications</a></p>
<p class="toc level2"><a href="bncas.html">30.&nbsp;&nbsp;Securing Web Applications</a></p>
<p class="toc level2"><a href="bncdq.html">31.&nbsp;&nbsp;The Java Message Service API</a></p>
<p class="toc level2"><a href="bncgv.html">32.&nbsp;&nbsp;Java EE Examples Using the JMS API</a></p>
<p class="toc level2"><a href="bncih.html">33.&nbsp;&nbsp;Transactions</a></p>
<p class="toc level2"><a href="bncjh.html">34.&nbsp;&nbsp;Resource Connections</a></p>
<p class="toc level2"><a href="bncjx.html">35.&nbsp;&nbsp;Connector Architecture</a></p>
<p class="toc level1 tocsp"><a href="bnckn.html">Part&nbsp;VII&nbsp;Case Studies</a></p>
<p class="toc level2"><a href="bncko.html">36.&nbsp;&nbsp;The Coffee Break Application</a></p>
<p class="toc level2"><a href="bnclz.html">37.&nbsp;&nbsp;The Duke's Bank Application</a></p>
<p class="toc level1 tocsp"><a href="gexbq.html">Part&nbsp;VIII&nbsp;Appendixes</a></p>
<p class="toc level2"><a href="bncno.html">A.&nbsp;&nbsp;Java Encoding Schemes</a></p>
<p class="toc level2"><a href="bncnq.html">B.&nbsp;&nbsp;Preparation for Java EE Certification Exams</a></p>
<p class="toc level2"><a href="bncnt.html">C.&nbsp;&nbsp;About the Authors</a></p>
<p class="toc level1 tocsp"><a href="idx-1.html">Index</a></p>
</td>
      <td width="10px">&nbsp;</td>
      <td width="705px">
         <div class="header">
             <div class="header-links-top">
                 <a href="http://java.sun.com">java.sun.com</a> |
                 <a href="http://docs.sun.com/">docs.sun.com</a><br>
             </div> 
             <img src="graphics/tutorialBanner.gif" width="704" height="120" alt="The Java&trade; EE 5 Tutorial"/>
             <div class="header-links">
	         <a href="index.html">Home</a> |
                 <a href="http://java.sun.com/javaee/5/docs/tutorial/information/download.html">Download</a> |
                 <a href="http://java.sun.com/javaee/5/docs/tutorial/doc/JavaEETutorial.pdf">PDF</a> |
                 <a href="http://java.sun.com/javaee/5/docs/api/index.html">API</a> |
                 <a href="http://java.sun.com/javaee/5/docs/tutorial/information/faq.html">FAQ</a> |
                 <a href="http://java.sun.com/javaee/5/docs/tutorial/information/search.html">Search</a> |
                 <a href="http://java.sun.com/javaee/5/docs/tutorial/information/sendusmail.html">Feedback</a> |
                 <a href="http://java.sun.com/javaee/5/docs/tutorial/information/history.html">History</a>
             </div>
             <div class="navigation">
                 <a href="bnali.html"><img style="padding-right: 3px" src="graphics/leftButton.gif" border="0"></a>
                 <a href="sjsaseej2eet.html"><img style="padding-right: 3px" src="graphics/upButton.gif" border="0"></a>
                 <a href="bnalk.html"><img style="padding-left: 3px" src="graphics/rightButton.gif" border="0"></a>
             </div>
         </div>

	 <div class="maincontent">      	 
             <a name="bnalj"></a><h3>Chapter&nbsp;8</h3><h3>Custom Tags in JSP Pages</h3><a name="indexterm-502"></a><p><a name="indexterm-503"></a><a name="indexterm-504"></a>The standard JSP tags simplify JSP page development and maintenance. JSP technology also
provides a mechanism for encapsulating other types of dynamic functionality in <b>custom tags</b>, which
are extensions to the JSP language. Some examples of tasks that can be
performed by custom tags include operating on implicit objects, processing forms, accessing databases and
other enterprise services such as email and directories, and implementing flow control. Custom
tags increase productivity because they can be reused in more than one application.</p><p><a name="indexterm-505"></a><a name="indexterm-506"></a><a name="indexterm-507"></a><a name="indexterm-508"></a><a name="indexterm-509"></a><a name="indexterm-510"></a><a name="indexterm-511"></a>Custom tags are distributed in a <b>tag library</b>, which defines a set of related custom
tags and contains the objects that implement the tags. The object that implements
a custom tag is called a <b>tag handler</b>. JSP technology defines two types of
tag handlers: simple and classic. <b>Simple</b> tag handlers can be used only
for tags that do not use scripting elements in attribute values or the
tag body. <b>Classic</b> tag handlers must be used if scripting elements are required.
Simple tag handlers are covered in this chapter, and classic tag handlers are
discussed in <a href="bnaon.html">Chapter&nbsp;9, Scripting in JSP Pages</a>.</p><p><a name="indexterm-512"></a><a name="indexterm-513"></a>You can write simple tag handlers using the JSP language or using the
Java language. A <b>tag file</b> is a source file containing a reusable fragment
of JSP code that is translated into a simple tag handler by the
web container. Tag files can be used to develop custom tags that are
presentation-centric or that can take advantage of existing tag libraries, or by page
authors who do not know Java. When the flexibility of the Java programming
language is needed to define the tag, JSP technology provides a simple API
for developing a tag handler in the Java programming language.</p><p>This chapter assumes that you are familiar with the material in <a href="bnagx.html">Chapter&nbsp;5, JavaServer Pages Technology</a>,
especially the section <a href="bnaiy.html">Using Custom Tags</a>. For more information about tag libraries and for pointers to
some freely available libraries, see <a href="http://java.sun.com/products/jsp/taglibraries/index.jsp">http://java.sun.com/products/jsp/taglibraries/index.jsp</a>.</p>
         </div>
         <div class="navigation">
             <a href="bnali.html"><img style="padding-right: 3px" src="graphics/leftButton.gif" border="0"></a>
             <a href="sjsaseej2eet.html"><img style="padding-right: 3px" src="graphics/upButton.gif" border="0"></a>
             <a href="bnalk.html"><img style="padding-left: 3px" src="graphics/rightButton.gif" border="0"></a>
         </div>

         <div class="copyright">
      	    <p>The material in The Java&trade; EE 5 Tutorial is <a href='docinfo.html'>copyright</a>-protected and may not be published in other works without express written permission from Sun Microsystems.</p>
      	 </div>

      </td>
   </tr>
</tbody>
</table>
</body>
</html>

